<?php

namespace JsonLowCode\UI;

use JsonLowCode\Schema;

/**
 *
 * 代码 Code
 * @method static Code make(string $code = null) Code组件
 */
class Code extends Schema
{
    protected string $componentName = "NCode";

    public function __construct(string $code = null)
    {
        parent::__construct();
        $this->code($code);
//        $this->hljs("window.hljs");
        $this->language("php");
    }

    /**
     * 使用行内样式
     * @param string|bool $bool
     * @return $this
     */
    public function inline(string|bool $bool = true): Code
    {
        return $this->prop('inline', $bool);
    }

    /**
     * 代码内容
     * @param string $code
     * @return $this
     */
    public function code(string $code): Code
    {
        return $this->prop('code', $code);
    }

    /**
     * 代码语言
     *  bash,c,cpp,csharp,css,diff,go,graphql,ini,java,javascript,json,kotlin,less,lua,makefile,
     *  markdown,objectivec,perl,php,php_template,plaintext,python,python_repl,r,ruby,rust,
     *  scss,_shell,sql,swift,typescript,vbnet,wasm,xml,yaml
     * @param string $language
     * @return $this
     */
    public function language(string $language = "php"|"go"|"python"|"javascript"|"javascript"|"json"|"java"|"css"|"less"|"scss"|"xml"|"sql"): Code
    {
        return $this->prop('language', $language);
    }

    /**
     * 如果你想局部设定 hljs，可以通过这个属性传给组件
     * @param string|array $hljs
     * @return $this
     */
    public function hljs(string|array $hljs = [],  bool $isJSExpression = true): Code
    {
        return $this->prop('hljs', $hljs);
    }

    /**
     * 是否显示行号，在 inline 或 word-wrap 的情况下不生效
     * @param string|bool $bool
     * @return $this
     */
    public function showLineNumbers(string|bool $bool = true): Code
    {
        return $this->prop('show-line-numbers', $bool);
    }

    /**
     * 是否显示 trim 后的代码
     * @param string|bool $bool
     * @return $this
     */
    public function trim(string|bool $bool = true): Code
    {
        return $this->prop('trim', $bool);
    }

    /**
     * 代码过长时是否自动换行
     * @param string|bool $bool
     * @return $this
     */
    public function wordWrap(string|bool $bool = true): Code
    {
        return $this->prop('word-wrap', $bool);
    }

    /**
     * 主题设置
     * @param string|null $theme
     * @return $this
     */
    public function theme(string $theme = null): Code
    {
        return $this->prop('theme', $theme);
    }

    /**
     * 主题设置
     * @param string|array|null $themeOverrides
     * @return $this
     */
    public function themeOverrides(string|array|null $themeOverrides = null): Code
    {
        return $this->prop('theme-overrides', $themeOverrides);
    }


}
